﻿using System.Text.RegularExpressions;
using Behaviorize.CodeGenerator.CodeModel;

namespace Behaviorize.CodeGenerator.TextInterpretation
{
	public static class Interpreter
	{
		public static CodeModel.Feature ParseSpecificationText(string text)
		{
			var featureRegex = new Regex(@"(?:^Feature:)(.*)((?:^Feature:|$))", RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
			var featureMatches = featureRegex.Matches(text);

			if (featureMatches.Count == 0) return null;

			Match featureMatch = featureMatches[0];

			if (!featureMatch.Success) return null;

			string featureText = featureMatch.Groups[1].Value;
			return FeatureFactory.Create(featureText);
		}
	}
}